﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading;

namespace WpfApplication1.StartPages
{
    /// <summary>
    /// Interaction logic for HighScore.xaml
    /// </summary>
    public partial class HighScoreScreen : UserControl, IIdleScreen
    {
        private Timer m_timer;
        private List<HighScore> m_highScores;

        public HighScoreScreen()
        {
            InitializeComponent();
            m_highScores = HighScore.Read();
            HighScoreList.ItemsSource = m_highScores;
        }


        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            m_timer = new Timer(new TimerCallback(this.TimeUp), null, 10000, 10000);
        }

        private void TimeUp(object status)
        {
            m_timer.Dispose();
            Action<EventArgs> del = new Action<EventArgs>(OnNext);
            App.Current.Dispatcher.Invoke(del, new object[] { new EventArgs() });
        }


        #region IIdleScreen Members

        public event EventHandler Next;
        public event EventHandler Begin;

        protected void OnNext(EventArgs e)
        {
            if (Next != null)
                Next(this, e);
        }

        protected void OnBegin(EventArgs e)
        {
            if (Begin != null)
                Begin(this, e);
        }

        void IIdleScreen.RegisterHit(double value)
        {
            OnBegin(new EventArgs());
        }

        #endregion

        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {
            MessageBox.Show("Starta");
            OnBegin(new EventArgs());
        }

    }
}
